import MeasureItem from './MeasureItem'
import Calc from './Calc'
import DateUtils from '../utils/DateUtils'
const UI = require('./UI')
var desc = "您的含水量为 XX公斤 ，处于YY状态，适量饮水，适当运动，均衡饮食，保持身体水分平衡。"
const STAND_LEVEL = 1
export default class WaterContentReport {
  /**
   * 含水量
   */
  static calcWaterContent(weight, water) {
    return (weight * water / 100).toFixed(2)
  }

  static initValues(measure) {
    let values;
    let weight = measure.weight;

    if (measure.gender == 1) {
      values = [WaterContentReport.calcWaterContent(weight, 55), WaterContentReport.calcWaterContent(weight, 65)]

    } else {
      values = [WaterContentReport.calcWaterContent(weight, 45), WaterContentReport.calcWaterContent(weight, 60)]

    }
    return values;
  }

  static isEnable(measure) {
    return true
  }

  static build(measure) {

    const item = new MeasureItem()
    const values = WaterContentReport.initValues(measure)
    const value = WaterContentReport.calcWaterContent(measure.weight, measure.water);
    const boundaries = values
    const level = Calc.calcLevel(value, boundaries, STAND_LEVEL)
    const isStand = level == STAND_LEVEL

    item.name = "含水量"
    item.boundaries = boundaries
    item.value = value
    item.levelNames = ["偏低", "标准", "充足"]
    item.isStand = isStand
    item.unit = "kg"
    item.desc = desc.replace("XX", item.value).replace("YY", item.levelNames[level])
    item.level = level
    item.bar = [UI.color.report_lower, UI.color.report_stand, UI.color.report_sufficient]

    item.min = 30
    item.max = 60
    item.levelName = item.levelNames[item.level]
    item.levelColor = item.bar[item.level]

    if (!isStand) {
      let offset = 0
      if (level < STAND_LEVEL) {
        offset = value - boundaries[STAND_LEVEL - 1]
      } else {
        offset = value - boundaries[STAND_LEVEL]
      }
      item.offset = offset
    }

    return item
  }

}



// WEBPACK FOOTER //
// ./src/report/WaterContent.js
